package servlet.manage.online;

import model.OnlineModel;
import net.sf.json.JSONArray;
import service.IOnlineService;
import service.impl.OnlineServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/OnlineAdd")
public class OnlineAddServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String name= req.getParameter("name");
        String email= req.getParameter("email");
        String content= req.getParameter("content");
        String phone= req.getParameter("phone");
        OnlineModel onlineModel =new OnlineModel();
        onlineModel.setName(name);
        onlineModel.setEmail(email);
        onlineModel.setContent(content);
        onlineModel.setPhone(phone);

        IOnlineService service =new OnlineServiceImpl();
        service.add(onlineModel);

        JSONArray jsonArray =JSONArray.fromObject(service.add(onlineModel));
        resp.getWriter().println(jsonArray);

    }
}
